package com.kadron.entity;

import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.validator.NotNull;

import com.kadron.base.KBase;

@Entity
@Table(name = "k_price", uniqueConstraints = { @UniqueConstraint(columnNames = {
		"item_id", "currency_id" }) })
public class Price extends KBase implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1990450313599525624L;

	private Item item;
	private Currency currency;
	private double price;
	
	public Price() {
		super();
	}

	public Price(Item item, Currency currency) {
		this();
		this.item = item;
		this.currency = currency;
	}
	
	@NotNull
	@ManyToOne(targetEntity = Item.class)
	@JoinColumn(name = "item_id")
	public Item getItem() {
		return item;
	}

	public void setItem(Item item) {
		this.item = item;
	}

	@NotNull
	@ManyToOne(targetEntity = Currency.class)
	@JoinColumn(name = "currency_id")
	public Currency getCurrency() {
		return currency;
	}

	public void setCurrency(Currency currency) {
		this.currency = currency;
	}

	@Basic
	@NotNull
	@Column(name = "price", nullable=false)
	public double getPrice() {
		return price;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result
				+ ((currency == null) ? 0 : currency.hashCode());
		result = prime * result + ((item == null) ? 0 : item.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Price other = (Price) obj;
		if (currency == null) {
			if (other.currency != null)
				return false;
		} else if (!currency.equals(other.currency))
			return false;
		if (item == null) {
			if (other.item != null)
				return false;
		} else if (!item.equals(other.item))
			return false;
		return true;
	}
	
}
